//
//  YPLogin_Api.swift
//  
//  模块请求Api
//  Created by ogawa on 2020/4/28.
//  Copyright © 2020 ogawa. All rights reserved.
//

import Foundation
import Moya

public enum YPLogin_Api {
    ///用户注册
    case register(phone: String, password: String,msgCode: String)
    ///用户登陆
    case login(phone: String, password: String)
    ///发送验证码
    case sendmsgcode(phone: String)
    ///修改密码
    case updatepassword(phone: String, password: String,msgCode: String)
    ///退出登陆
    case logout
}

extension YPLogin_Api: TargetType {

//    var baseURL: URL {
//        return 'http://www.baidu.com'.url!
//    }
    
    //请求路径
    public var path: String {
        switch self {
        case .register:
            return "user/register"
        case .login:
            return "user/login"
        case .sendmsgcode:
            return "user/sendmsgcode"
        case .updatepassword:
            return "user/updatepassword"
        case .logout:
            return "user/logout"
        }
    }

    ///设置请求方式 get post等
    public var method: Moya.Method {
        switch self {
        default:
            return .post
        }
    }
    
    ///设置头部参数
    public var headers: [String: String]? {
        return nil
    }
    
    ///设置请求参数
    public var parameters: [String: Any]? {
        switch self {
            case .register(let phone, let password , let msgCode):
                return ["phone": phone, "password": password, "msgCode": msgCode]
            case .login(phone: let phone, password: let password):
                return ["phone": phone, "password": password]
            case .sendmsgcode(phone: let phone):
                return ["phone": phone]
            case .updatepassword(phone: let phone, password: let password, msgCode: let msgCode):
                return ["phone": phone, "password": password, "msgCode": msgCode]
            default:
                return nil;
        }
    }
    
}

